package com.example.controller;

import com.graduation.vo.EmployeeVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Objects;

@Controller
public class RouterController {

    @RequestMapping("/index")
    public String index() {
        return "index";
    }

    @RequestMapping("/main")
    public String toMainView(HttpSession session, HttpServletRequest request) {
        EmployeeVO loginer = (EmployeeVO) session.getAttribute("loginer");
        if (Objects.isNull(loginer)) {
            request.setAttribute("loginInfo", "用户已退出，请重新登录");
            return "index";
        } else {
            request.setAttribute("loginerAccount", loginer.getAccount());
            return "base/main";
        }
    }
}
